package com.llbnk.srb.core.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.llbnk.common.result.R;
import com.llbnk.srb.core.pojo.entity.Borrower;
import com.llbnk.srb.core.pojo.vo.BorrowerApprovalVO;
import com.llbnk.srb.core.pojo.vo.BorrowerDetailVO;
import com.llbnk.srb.core.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author shkstart
 * @create 2022-04-17 21:57
 */
@Api(tags = "借款人管理")
@RestController
@RequestMapping("/admin/core/borrower")
@Slf4j
public class AdminBorrowerController {

    @Resource
    private BorrowerService borrowerService;

    @ApiOperation("获取借款人分页列表")
    @GetMapping("/list/{page}/{limit}")
    public R listPage(
            @ApiParam(value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(value = "每页记录数", required = true)
            @PathVariable Long limit,

            //之前在AdminUserInfoController实现展示在后台管理页面上可以查询会员信息设置状态
            //这个地方关键字只有一个是手机号/手机/身份证（AdminUserInfoController是三个参数）
            @ApiParam(value = "查询关键字", required = false)
            @RequestParam String keyword) {
        //这个地方的代码和AdminUserInfoController的listPage几乎一摸一样
        Page<Borrower> pageParam = new Page<>();
        IPage<Borrower> pageModel = borrowerService.listPage(pageParam,keyword);
        return R.ok().data("pageModel",pageModel);
    }

    //这个接口是用来展示额度审批页面的借款人详情
    //http://localhost:9528/#/core/borrower/detail/1
    // 最后一位可以得到borrow对象的id，之后就把borrow的信息取出来就可以了
    @ApiOperation("获取借款人信息")
    @GetMapping("/show/{id}")
    public R show(
            @ApiParam(value = "借款人id" , required = true)
            @PathVariable Long id
    ){
        BorrowerDetailVO borrowerDetailVO = borrowerService.getBorrowerDetailVOById(id);
        return R.ok().data("borrowerDetailVO",borrowerDetailVO);
    }

    //这个接口是用来展示额度审批页面是否审核通过
    @ApiOperation("借款人额度审批")
    @PostMapping("/approval")
    public R approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO){
        borrowerService.approval(borrowerApprovalVO);
        return R.ok().message("审批完成");
    }



}

